package com.situ.skymall.admin.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.model.User;
import com.situ.model.UserAddress;
import com.situ.skymall.admin.api.service.UserFeignService;
import com.situ.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/api/v1/address")
public class UserAddressController {

    private final UserFeignService userFeignService;

    @Autowired
    public UserAddressController(UserFeignService userFeignService) {
        this.userFeignService = userFeignService;
    }

    /**
     * 获取用户的所有地址
     */
    @GetMapping("/list/{userId}")
    public JsonResult<List<UserAddress>> getAddressListByUserId(@PathVariable Integer userId) {
        return userFeignService.getAddressListByUserId(userId);
    }

    /**
     * 获取用户的默认地址
     */
    @GetMapping("/default/{userId}")
    public JsonResult<UserAddress> getDefaultAddress(@PathVariable Integer userId) {
        return userFeignService.getDefaultAddress(userId);
    }

    /**
     * 设置默认地址
     */
    @PutMapping("/default")
    public JsonResult<String> setDefaultAddress(@RequestParam Integer userId, @RequestParam Integer addressId) {
        return userFeignService.setDefaultAddress(userId, addressId);
    }

    /**
     * 新增用户地址
     */
    @PostMapping("/add")
    public JsonResult<String> addAddress(@RequestBody UserAddress userAddress) {
        return userFeignService.addAddress(userAddress);
    }

    /**
     * 修改用户地址
     */
    @PutMapping("/update")
    public JsonResult<String> updateAddress(@RequestBody UserAddress userAddress) {
        return userFeignService.updateAddress(userAddress);
    }

    /**
     * 删除用户地址
     */
    @DeleteMapping("/delete/{id}")
    public JsonResult<String> deleteAddress(@PathVariable Integer id) {
        return userFeignService.deleteAddress(id);
    }
}
